package io.renren.modules.examination.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.examination.dao.ExaminationResultTypeDao;
import io.renren.modules.examination.entity.ExaminationResultTypeEntity;
import io.renren.modules.examination.service.ExaminationResultTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("examinationResultTypeService")
public class ExaminationResultTypeServiceImpl extends ServiceImpl<ExaminationResultTypeDao, ExaminationResultTypeEntity> implements ExaminationResultTypeService {

    @Autowired
    ExaminationResultTypeDao examinationResultTypeDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ExaminationResultTypeEntity> page = this.selectPage(
                new Query<ExaminationResultTypeEntity>(params).getPage(),
                new EntityWrapper<ExaminationResultTypeEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByPaperId(Map<String, Object> params, Integer paperId) {
        PageUtils page=new PageUtils();
        int total=examinationResultTypeDao.getExaminationResultTypeTotalByPaperId(params, paperId);
        page.setPageSize(Integer.parseInt((String) params.get("limit")));
        page.setList(examinationResultTypeDao.getExaminationResultTypeListByPaperId(params, paperId));
        page.setTotalCount(total);
        page.setCurrPage(Integer.parseInt((String) params.get("page")));
        page.setTotalPage(Constant.getTotalPage(page.getTotalCount(),page.getPageSize()));
        return page;
    }

    @Override
    public PageUtils getExaminationResultTypeList(Map<String, Object> params) {
        PageUtils page=new PageUtils();
        int total=examinationResultTypeDao.getExaminationResultTypeTotal(params);
        page.setPageSize(Integer.parseInt((String) params.get("limit")));
        page.setList(examinationResultTypeDao.getExaminationResultTypeList(params));
        page.setTotalCount(total);
        page.setCurrPage(Integer.parseInt((String) params.get("page")));
        page.setTotalPage(Constant.getTotalPage(page.getTotalCount(),page.getPageSize()));
        return page;
    }

}
